<?php
/**
 * Criado em 09/10/2009
 * CoordenadorDAO.php
 */
 class CoordenadorDAO {

 	/**
	 * Get Domain object by primry key
	 *
	 * @param String $id primary key
	 * @return Coordenador
	 */
	public function load($id){
		$sql = 'SELECT * FROM coordenador WHERE codCoordenador = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($id);
		return $this->getRow($sqlQuery);
	}

	/**
	 * Get all records from table
	 */
	public function queryAll(){
		$sql = 'SELECT * FROM coordenador';
		$sqlQuery = new SqlQuery($sql);
		return $this->getList($sqlQuery);
	}

	/**
	 * Get all records from table ordered by field
	 *
	 * @param $orderColumn column name
	 */
	public function queryAllOrderBy($orderColumn){
		$sql = 'SELECT * FROM coordenador ORDER BY '.$orderColumn;
		$sqlQuery = new SqlQuery($sql);
		return $this->getList($sqlQuery);
	}

	/**
	 * Read row
	 *
	 * @return Coordenador
	 */
	protected function readRow($row) {
		$coordenador = new Coordenador();

		$coordenador->codCoordenador = $row['codCoordenador'];
		$coordenador->nomeCoordenador = $row['nomeCoordenador'];

		return $coordenador;
	}

	protected function getList($sqlQuery) {
		$tab = QueryExecutor :: execute($sqlQuery);
		$ret = array ();
		for ($i = 0; $i < count($tab); $i++) {
			$ret[$i] = $this->readRow($tab[$i]);
		}
		return $ret;
	}

	/**
	 * Get row
	 *
	 * @return Coordenador
	 */
	protected function getRow($sqlQuery) {
		$tab = QueryExecutor :: execute($sqlQuery);
		return $this->readRow($tab[0]);
	}

	/**
	 * Execute sql query
	 */
	protected function execute($sqlQuery) {
		return QueryExecutor :: execute($sqlQuery);
	}

	/**
	 * Execute sql query
	 */
	protected function executeUpdate($sqlQuery) {
		return QueryExecutor :: executeUpdate($sqlQuery);
	}

	/**
	 * Insert row to table
	 */
	protected function executeInsert($sqlQuery) {
		return QueryExecutor :: executeInsert($sqlQuery);
	}

	/**
	 * obterNomeCoordenador
	 */
	public function obterNomeCoordenador($codCoordenador) {
		$sql = 'SELECT codCoordenador, nomeCoordenador FROM coordenador WHERE codCoordenador = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($codCoordenador);
		return $this->getList($sqlQuery);
	}

 }
?>
